import * as THREE from 'three'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js'
//碰撞
import { Octree } from 'three/examples/jsm/math/Octree.js'
import { Capsule } from 'three/examples/jsm/math/Capsule.js'
// import * as dat from 'dat.gui';
// 导入dat.gui库
import * as dat from 'dat.gui';

export const mixins = {
  data() {
    return {
      cameras: null,
      planeTop: null,
      planeBottom: null,
      cylinder: null,
      scale: 0,
      translateX:0,
      translate: 0,
      theWidth: 1,
      theHeight:1,
      params: { // 存储参数
        topPlaneX: -0.68,
        topPlaneY: 1.5,
        topPlaneZ: -0.15,
        bottomPlaneX: -0.68,
        bottomPlaneY: 0.84,
        bottomPlaneZ: -0.15
      },
      geometryTop: null,
      geometryBottom: null,
      XianShuChuiZhiCeShiTong_1: null,
      ZhunZhiDuJianCeBan: null,
      PingBanTanCeQi:null
      
    };
    
  },

  created() {},
    mounted() { },
    beforeDestroy() {
  
    clearTimeout()
    try {
      this.scene.clear()
      this.render.dispose()
      this.render.forceContextLoss()
      this.render.content = null
      // cancelAnimationFrame(animationID) // 去除animationFrame
      const gl = this.render.domElement.getContext('webgl')
      gl && gl.getExtension('WEBGL_lose_context').loseContext()
    } catch (e) {
      console.log(e)
    }
  },
  watch: {
    theWidth() {
      console.log('监听到值变化');
      this.getLine(true)
        this.planeTop.visible = true
      this.cylinder.visible = true
      this.planeBottom.visible = true
      //  this.animate()
			},
    theHeight() {		
         console.log('监听到值变化2');
      this.getLine(true)
      //  this.animate()
        this.planeTop.visible = true
      this.cylinder.visible = true
      this.planeBottom.visible = true
			},
  },
      computed: {
    getPosition() {
      //根据返回的位置信息计算物品提示小标位
      let maincontWidth = this.$el.offsetWidth
      let maincontHeight = this.$el.offsetHeight
      let leftPercentage = ((this.tipPosition.x + 25) / maincontWidth) * 100
      let topPercentage = ((this.tipPosition.y - 30) / maincontHeight) * 100
      return 'left:' + leftPercentage + '%;top:' + topPercentage + '%;'
    }
  },
    methods: {
            //初始化
    init() { 
      this.initSence()
      this.raycaster = new THREE.Raycaster() // 设置光线拾取
      this.clock = new THREE.Clock()
      this.mouse = new THREE.Vector2()
        },
            //初始化相机
    initCeremar() {
      const camera = new THREE.PerspectiveCamera(
        50,
        window.innerWidth / window.innerHeight,
        0.01,
        10000
      )
      camera.position.set(
        this.cameraOriginal[0],
        this.cameraOriginal[1],
        this.cameraOriginal[2]
      )

      this.camera = camera;
      this.scene.add(this.camera);
      this.cameras = this.camera 
       this.move(
          [-1.696, 1.369, -3.110],
          [-175.59   / 180, 4.87   / 180, 179.62   / 180]
        )
      // this.
    },
    //初始化场景
    initSence() {
     var scene = new THREE.Scene();
				scene.background = new THREE.Color(0xffffff);
      this.scene = scene;
       this.getTop()
       this.initLight()
      this.initCeremar()
      this.initRenderer()
       this.initMass()
      this.initCotronl()
      this.initPoint()
    // this.animate(); //刷新场景
      this.initFile()
      // this.initGUI();
      // this.initFileS(0)

     
      },

    //初始化渲染器
    initRenderer() {


       this.render = new THREE.WebGLRenderer({
        antialias: true,
       
        // logarithmicDepthBuffer: true
      })
      this.render.setClearColor(0xaaaaaa);
      this.render.setPixelRatio(window.devicePixelRatio*2)
       this.render.setSize(window.innerWidth, window.innerHeight)
      this.render.shadowMap.enabled = true
      this.render.shadowMap.type = THREE.PCFSoftShadowMap;
      
      this.render.toneMapping = THREE.ACESFilmicToneMapping;
        this.render.toneMappingExposure = 1.2
      // this.render.outputEncoding = THREE.LinearSRGBColorSpace
  
      this.render.outputColorSpace = THREE.SRGBColorSpace
      
       this.$el.appendChild(this.render.domElement)
    window.addEventListener('resize', this.onWindowResize) //监听窗口变化
    
      },
        //根据屏幕尺寸变化自适应
        onWindowResize() {
      //浏览器窗口大小改变后重新计算
      this.maincontWidth = this.$el.offsetWidth
      this.maincontHeight = this.$el.offsetHeight
      this.maincontSc = this.maincontWidth / this.maincontHeight
      this.camera.aspect = this.maincontSc
      this.camera.updateProjectionMatrix()
      this.render.setSize(this.maincontWidth, this.maincontHeight)
    }, //鼠标移动6+射线拾取
    //初始化控制器
    initCotronl() {
  

      this.mouse = new THREE.Vector2() //获取鼠标 位置二维坐标信息
      document.body.addEventListener('mousemove', this.onDocumentMouseMove)
      document.body.addEventListener('mousedown', this.onDocumentMouseDown)
      this.$el.addEventListener('mouseup', this.onDocumentMouseUp)
     

    }, //初始化物体
      initFile() {
      this.$emit('loadingfn', true);
      let gltfloader = new GLTFLoader()
      this.app = gltfloader
      const dracoLoader = new DRACOLoader()
      // dracoLoader.setDecoderPath('/draco/')
      dracoLoader.setDecoderPath(
       window.config.VUE_GLB_Base_load
      )
      dracoLoader.preload()
      gltfloader.setDRACOLoader(dracoLoader)
      gltfloader.load(window.config.VUE_GLB_Base + 'DRchangjing.glb', (gltf) => {
        this.model = gltf.scene
      this.objectReItem = gltf.scene
        gltf.scene.position.set(0, 0, 0)
        if (this.worldOctree) {
          this.worldOctree.fromGraphNode(this.objectReItem)
        }
         if (gltf.scene.children[3].name == 'LiangDuXingKa') { 
           this.LiangDuXingKa_3 = gltf.scene.children[3]
              this.LiangDuXingKa_3.visible = false
        }
        gltf.scene.traverse((child) => {
          if (child.isMesh) {
            // child.receiveShadow = true
            // child.castShadow = true
            child.material.emissiveMap = child.material.map
            if (this.objectNames.includes(child.name)) {
              //将需要检查到的模型放到objects
              this.objects.push(child)
            }
            // if (child.name == 'gxspy_zhuozi') {
            //   child.material.emissive = child.material.color
            //   child.material.emissiveMap = child.material.map
            // }
            // if (child.name == 'XianShuChuiZhiCeShiTong_1') { 
            //   this.XianShuChuiZhiCeShiTong_1 = child
            //   this.XianShuChuiZhiCeShiTong_1.visible =false
            // }
            // if (child.name == 'ZhunZhiDuJianCeBan') { 
            //   this.ZhunZhiDuJianCeBan = child
            //   this.ZhunZhiDuJianCeBan.visible =false
            // }
            if (child.name == 'gxspy_zhuozi') {
              child.material.emissive = child.material.color
              child.material.emissiveMap = child.material.map
            }
            if (child.name == 'XianShuChuiZhiCeShiTong_1') { 
              this.XianShuChuiZhiCeShiTong_1 = child
              this.XianShuChuiZhiCeShiTong_1.visible =false
            }
            if (child.name == 'ZhunZhiDuJianCeBan') { 
              this.ZhunZhiDuJianCeBan = child
              this.ZhunZhiDuJianCeBan.visible =false
            }
            if (child.name == 'PingBanTanCeQi') { 
              this.PingBanTanCeQi = child
              this.PingBanTanCeQi.visible =false
              }
              if (child.name == 'DiFenBianLvJianCeMoTi') { 
                  this.DiFenBianLvJianCeMoTi = child
                  this.DiFenBianLvJianCeMoTi.visible = false
              }
              if (child.name == 'FenBianLvCeShiKa') { 
                  this.FenBianLvCeShiKa = child
                  this.FenBianLvCeShiKa.visible = false
            }
           
           
            if (child.name == 'WuPinTai') { 
              this.WuPinTai = child
              this.WuPinTai.visible  = false
            }
            // if (child.name == 'PingBanTanCeQi') { 
            //   this.PingBanTanCeQi = child
            //   this.PingBanTanCeQi.visible =false
            // }
            //设置模型自发光
            // child.material.emissive = child.material.color
          }
        })
        this.scene.add(gltf.scene)
        // this.render.render(this.scene, this.camera)
        // this.$emit('loadingfn', false);  
        // this.animate()
        this.initBox();
      }
    
        )
          gltfloader.load(window.config.VUE_GLB_Base + 'DR1.glb', (gltf) => {
        this.model = gltf.scene
      this.objectReItem = gltf.scene
        gltf.scene.position.set(0, 0, 0)
        if (this.worldOctree) {
          this.worldOctree.fromGraphNode(this.objectReItem)
        }
        gltf.scene.traverse((child) => {
          if (child.isMesh) {
            child.receiveShadow = true
            child.castShadow = true
            child.material.emissiveMap = child.material.map
            if (this.objectNames.includes(child.name)) {
              //将需要检查到的模型放到objects
              this.objects.push(child)
            }
            if (child.name == 'gxspy_zhuozi') {
              child.material.emissive = child.material.color
              child.material.emissiveMap = child.material.map
            }
            //设置模型自发光
            // child.material.emissive = child.material.color
          }
        })
        this.scene.add(gltf.scene)
     
        this.$emit('loadingfn', false);
         this.animate()
     this.render.render(this.scene, this.camera)
        this.initBox();
      
      } )
        
      },
        initGUI() {
      // 创建一个GUI实例
      this.gui = new dat.GUI();

      // 将参数添加到GUI中，并指定范围和步长
      const folder = this.gui.addFolder('Planes Position');
      folder.add(this.params, 'topPlaneX', -2, 2).name('Top Plane X').onChange(this.updatePosition);
      folder.add(this.params, 'topPlaneY', -2, 2).name('Top Plane Y').onChange(this.updatePosition);
      folder.add(this.params, 'topPlaneZ', -2, 2).name('Top Plane Z').onChange(this.updatePosition);
      folder.add(this.params, 'bottomPlaneX', -2, 2).name('Bottom Plane X').onChange(this.updatePosition);
      folder.add(this.params, 'bottomPlaneY', -2, 2).name('Bottom Plane Y').onChange(this.updatePosition);
      folder.add(this.params, 'bottomPlaneZ', -2, 2).name('Bottom Plane Z').onChange(this.updatePosition);
      folder.open();
    },
      updatePosition() {
      console.log('更新了平面位置及信息啦');
      // 更新顶部和底部平面的位置
      this.geometryTop.translate(this.params.topPlaneX, this.params.topPlaneY, this.params.topPlaneZ);
      this.geometryBottom.translate(this.params.bottomPlaneX, this.params.bottomPlaneY, this.params.bottomPlaneZ);
      // 重新渲染场景或者刷新应用程序
      this.animate();
    },
      getTop() {
				// var that = this;
				var material = new THREE.MeshBasicMaterial({
					color: 0x00D1FF,
					side: THREE.DoubleSide,
					transparent: true, // 设置为true，opacity才会生效
					opacity: 0.2,
					depthWrite: false, // 不遮挡后面的模型
				});

				var geometryTop = new THREE.PlaneGeometry(0.1, 0.1);
        geometryTop.rotateX(Math.PI * 0.5);
        this.geometryTop = geometryTop
        // geometryTop.translate(-0.684, 1.35, -0.050)
        this.geometryTop.translate(this.params.topPlaneX, this.params.topPlaneY, this.params.topPlaneZ);
				var planeTop = new THREE.Mesh(this.geometryTop, material);
				this.scene.add(planeTop);
				this.planeTop = planeTop;
				this.getLine(true)
        
      },
      	getLine(init) {
				// if(!init) {
				// 	this.cylinder.removeFromParent();
				// 	this.planeBottom.removeFromParent();
          //   }
          if (this.cylinder && this.planeBottom) { 
  this.cylinder.removeFromParent();
					this.planeBottom.removeFromParent();
          }
        
				// var that = this;
				var material = new THREE.MeshBasicMaterial({
					color: 0x00D1FF,
					side: THREE.DoubleSide,
					transparent: true, // 设置为true，opacity才会生效
					opacity: 0.2,
					depthWrite: false, // 不遮挡后面的模型
				});

				var boxHeight = 0.1 * this.theHeight + 0.1;
				var boxWidth = 0.1 * this.theWidth + 0.1;
				var geometryBottom = new THREE.PlaneGeometry(boxWidth, boxHeight);
				geometryBottom.rotateX(Math.PI * 0.5);
          // geometryBottom.translate(-0.684, 0.84, -0.050);
          this.geometryBottom = geometryBottom
           this.geometryBottom.translate(this.params.bottomPlaneX, this.params.bottomPlaneY, this.params.bottomPlaneZ);
				var planeBottom = new THREE.Mesh(this.geometryBottom, material);
				this.scene.add(planeBottom);
          this.planeBottom = planeBottom;
          this.planeBottom.visible = false
          console.log('planeBottom',planeBottom);

				var geometryTopArr = this.planeTop.geometry.getAttribute('position').array;
				var geometryBottomArr = this.planeBottom.geometry.getAttribute('position').array;
				var verticesArr = this.getAll(geometryTopArr, geometryBottomArr);
				const geometryNew = new THREE.BufferGeometry();
				const vertices = new Float32Array(verticesArr);
				geometryNew.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
				var cylinder = new THREE.Mesh(geometryNew, material);
				if(init) {
					 cylinder.visible = false;
				}
          this.scene.add(cylinder);
         
          this.cylinder = cylinder;
          
			},
			getAll(vertices1, vertices2) {
				var that = this;
				var verticesAll = [];
				var indexArr = [
					[0, 1],
					[1, 3],
					[2, 3],
					[1, 4]
				]
				for(var i = 0; i < indexArr.length; i++) {
					var start = indexArr[i][0];
					var end = indexArr[i][1];
					var endAll = indexArr[i][1] == 3 ? false : true;
					var point1 = vertices1.slice(start * 3, (start + 1) * 3);
					var point2 = endAll ? vertices1.slice(end * 3, (end + 1) * 3) : vertices1.slice(end * 3);
					var point3 = vertices2.slice(start * 3, (start + 1) * 3);
					var point4 = endAll ? vertices2.slice(end * 3, (end + 1) * 3) : vertices2.slice(end * 3);
					var itemArr = that.getOne(point1, point2, point3, point4);
					verticesAll = [...verticesAll, ...itemArr]
				}
				return verticesAll

			},
			getOne(point1, point2, point3, point4) {
				var newArr = [...point1, ...point2, ...point3, ...point2, ...point3, ...point4, ...point3, ...point4, ...point1, ...point4, ...point1, ...point2];
				return newArr
			},
      destroyOldScene() { 
        if (this.objectFather) {
          this.scene.remove(this.objectFather.scene)
          this.objectFather.scene.traverse((child) => {
            if (child.material) {
              child.material.dispose()
            }
            if (child.geometry) {
              child.geometry.dispose()
            }
            child = null
          })

          this.objectFather = null
        }
      },
    //根据步骤渲染物体和动画
      initFileS(index) {
      
           this.$emit('loadingfn', true);
       
      let gltfloader = new GLTFLoader()
      const dracoLoader = new DRACOLoader()
      // dracoLoader.setDecoderPath('/draco/')
      dracoLoader.setDecoderPath(
       window.config.VUE_GLB_Base_load
      )
      dracoLoader.preload()
      gltfloader.setDRACOLoader(dracoLoader)
      gltfloader.load(window.config.VUE_GLB_Base + this.dhfiles[index].url, (gltf) => {
        this.destroyOldScene()
         
         if (this.worldOctree) {
          this.worldOctree.fromGraphNode(gltf.scene)
        }
        gltf.scene.position.set(0, 0, 0)
        this.objects = []
        gltf.scene.traverse((child) => {
          if (child.isMesh) {
            child.castShadow = false
            child.receiveShadow = true
            child.castShadow = true
            if (this.objectNames.includes(child.name)) {
              //将需要检查到的模型放到objects
              this.objects.push(child)
            }
          
            child.material.emissiveMap = child.material.map
            // child.material.emissive = child.material.color
          }
        })
        this.scene.add(gltf.scene)
        this.objectFather = gltf
        this.andh = gltf.animations
        console.log('动画数据', gltf.animations)
        this.render.render(this.scene, this.camera)
     
           this.$emit('loadingfn', false);
     
         
        
        // this.initDragControls(this.Farray) //初始化拖拽控制器
      })
        },

        //初始化灯光
      initLight() {
      
     

           const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
      this.scene.add(ambientLight);
      const directionalLight1 = new THREE.DirectionalLight(0xffffff, 0.36);
      // directionalLight1.position.set(0.5, 2, 1);
         directionalLight1.position.set(0.05, -0.65, 2.7);
      directionalLight1.castShadow = true;
      this.scene.add(directionalLight1);
      const directionalLight2 = new THREE.DirectionalLight(0xffffff, 0.34);
      directionalLight2.position.set(-11.2, -4.6, -2);
      directionalLight2.castShadow = false;
      this.scene.add(directionalLight2);
      const directionalLight3 = new THREE.DirectionalLight(0xffffff, 0.3);
      directionalLight3.position.set(0.5, 1.6, -3);
      directionalLight3.castShadow = true;
        this.scene.add(directionalLight3);
        // 	const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
				// this.scene.add(ambientLight);
				// const directionalLight1 = new THREE.DirectionalLight(0xffffff, 0.5);
				// directionalLight1.position.set(0.5, 2, 1);
				// directionalLight1.castShadow = true;
				// this.scene.add(directionalLight1);
				// const directionalLight2 = new THREE.DirectionalLight(0xffffff, 0.3);
				// directionalLight2.position.set(-1, 5, -9);
				// directionalLight2.castShadow = false;
				// this.scene.add(directionalLight2);
				// const directionalLight3 = new THREE.DirectionalLight(0xffffff, 0.2);
				// directionalLight3.position.set(-1, 2, -3);
				// directionalLight3.castShadow = true;
				// this.scene.add(directionalLight3);

  
    },
    initPoint() {
      //初始换加载箭头指示图标
      const spriteImageLabel = (image) => {
        let textureLoader = new THREE.TextureLoader()
        const imageTexture = textureLoader.load(image)
        return imageTexture
      }
      let imgUrl = require('@/images/pointer.png')
      const spriteMap = spriteImageLabel(imgUrl)
      const spriteMaterial = new THREE.SpriteMaterial({
        map: spriteMap,
        color: 0xffffff
      })
      const sprite = new THREE.Sprite(spriteMaterial)
      sprite.scale.set(0.1, 0.1, 0.1)
      sprite.rotation.set(0, 0, Math.PI * 0.6)
      sprite.visible = false
      this.sprite = sprite
      this.scene.add(sprite)
        },
        //根据按钮播发动画
      playAction(animationName, realName) {
        console.log('播放了动画名称',animationName,'点击的物体',realName);
      this.playIng = true
      const theMixer = new THREE.AnimationMixer(this.objectFather.scene) //动画的物体
      const clip = THREE.AnimationClip.findByName(
        this.objectFather.animations,
        animationName
      ) //要播放的动画名称
      const action = theMixer.clipAction(clip)
      action.loop = THREE.LoopOnce //动画只执行一次
      action.clampWhenFinished = true //播放完成之后自动结束
      action.play()
      this.action = action
      theMixer.addEventListener('finished', () => {
        return setTimeout(() => {
          this.playIng = false
          this.$emit('clickItem', realName)
           console.log('动画播放完成')
        }, 600)
      })
      this.theMixer = theMixer
        },
     //循环渲染
    animate() {
      //镜头移动相关
      const deltaTime = Math.min(0.05, this.clock.getDelta())
      var oldPosition = JSON.parse(JSON.stringify(this.camera.position))
      requestAnimationFrame(this.animate)

      this.changeControls(deltaTime)

      // 开启漫游
      if (this.myshow) { 
         this.updatePlayer(deltaTime)
      }

      this.teleportPlayerIfOob()
      this.render.render(this.scene, this.camera)

      var newPosition = JSON.parse(JSON.stringify(this.camera.position))
      if (this.coverBox && this.areaCheck) {
        if (!this.coverBox.containsPoint(newPosition)) {
          this.camera.position.set(oldPosition.x, oldPosition.y, oldPosition.z)
        }
      }
      if (this.theMixer) {
        //动画渲染  3000 控制动画没一帧之间的时长
        this.theMixer.update(this.clock.getDelta())
        // this.clock.getDelta()
      }
      //清空原本动画事件，回调animate方法
      if (this.outLineAnimationFrameID) {
        window.cancelAnimationFrame(this.outLineAnimationFrameID)
      }
      this.outLineAnimationFrameID = requestAnimationFrame(this.animate)
        },
     // 漫游代码
    initBox() {
      var box = new THREE.Box3();
      box.setFromObject(this.objectReItem);
      this.coverBox = box;
    },
    initMass() {
      this.worldOctree = new Octree()
      this.playerCollider = new Capsule(
        new THREE.Vector3(
          this.cameraOriginal[0],
          this.cameraOriginal[1],
          this.cameraOriginal[2]
        ),
        new THREE.Vector3(
          this.cameraOriginal[0],
          this.cameraOriginal[1] + 1,
          this.cameraOriginal[2]
        ),
        0.35
      )
      this.playerVelocity = new THREE.Vector3()
      this.playerDirection = new THREE.Vector3()
    },
    playerCollisions() {
      const result = this.worldOctree.capsuleIntersect(this.playerCollider)
      this.playerOnFloor = false
      if (result) {
        this.playerOnFloor = result.normal.y > 0
        if (!this.playerOnFloor) {
          this.playerVelocity.addScaledVector(
            result.normal,
            -result.normal.dot(this.playerVelocity)
          )
        }
        this.playerCollider.translate(
          result.normal.multiplyScalar(result.depth)
        )
      }
    },
    updatePlayer(deltaTime) {
      let damping = Math.exp(-4 * deltaTime) - 1
      if (!this.playerOnFloor) {
        this.playerVelocity.y -= this.GRAVITY * deltaTime
        damping *= 0.1
      }
      this.playerVelocity.addScaledVector(this.playerVelocity, damping)
      const deltaPosition = this.playerVelocity
        .clone()
        .multiplyScalar(deltaTime)
      this.playerCollider.translate(deltaPosition)
      this.playerCollisions()
      this.camera.position.copy(this.playerCollider.end)
    },
    getForwardVector() {
      this.camera.getWorldDirection(this.playerDirection)
      this.playerDirection.y = 0
      this.playerDirection.normalize()
      return this.playerDirection
    },
    getSideVector() {
      this.camera.getWorldDirection(this.playerDirection)
      this.playerDirection.y = 0
      this.playerDirection.normalize()
      this.playerDirection.cross(this.camera.up)
      return this.playerDirection
    },
    // wasd位移
    changeControls(deltaTime) {
      const speedDelta = deltaTime * (this.playerOnFloor ? 25 : 8)
      if (this.keyStates['KeyW']) {
        this.playerVelocity.add(
          this.getForwardVector().multiplyScalar(speedDelta)
        )
      }
      if (this.keyStates['KeyS']) {
        this.playerVelocity.add(
          this.getForwardVector().multiplyScalar(-speedDelta)
        )
      }
      if (this.keyStates['KeyA']) {
        this.playerVelocity.add(
          this.getSideVector().multiplyScalar(-speedDelta)
        )
      }
      if (this.keyStates['KeyD']) {
        this.playerVelocity.add(this.getSideVector().multiplyScalar(speedDelta))
      }
      if (this.playerOnFloor) {
        if (this.keyStates['Space']) {
          this.playerVelocity.y = 6
        }
      }
    },
    teleportPlayerIfOob() {
      if (this.camera.position.y <= -15) {
        this.playerCollider.start.set(
          this.cameraOriginal[0],
          this.cameraOriginal[1],
          this.cameraOriginal[2]
        )
        this.playerCollider.end.set(
          this.cameraOriginal[0],
          this.cameraOriginal[1] + 1,
          this.cameraOriginal[2]
        )
        this.playerCollider.radius = 0.35
        this.camera.position.copy(this.playerCollider.end)
      }
      },
    stopAndReleaseAnimations() {
      if (this.andh && this.andh.length > 0) {
    
    this.theMixer.stopAllAction();
    this.theMixer.uncacheAction(this.action);
    // 停止动画
    this.andh.forEach((animation) => {
      animation.stop();
    });

    // 清空动画数组
    this.andh = [];

    // 释放资源
    this.renderer.dispose(); // 如果使用WebGLRenderer，可以释放Renderer的资源
    this.objects.forEach((object) => {
      if (object.geometry) {
        object.geometry.dispose();
      }
      if (object.material) {
        object.material.dispose();
      }
    });
    this.objects = [];

    // 其他可能的资源释放逻辑

    console.log('当前播放的动画已停止并释放资源');
  }
}
    }
};